﻿#region Copyright information
// 
// Copyright © 2005-2013 Yongkee Cho. All rights reserved.
// 
// This code is a part of the Biological Object Library and governed under the terms of the
// GNU Lesser General  Public License (LGPL) version 2.1 which accompanies this distribution.
// For more information on the LGPL, please visit http://bol.codeplex.com/license.
// 
// - Filename: DiagonalMatrix.cs
// - Author: Yongkee Cho
// - Email: yongkeecho@gmail.com
// - Date Created: 2012-11-05 11:21 AM
// - Last Modified: 2013-01-25 3:59 PM
// 
#endregion
using System;
using System.Collections.Generic;
using System.Linq;

namespace BOL.Linq.Matrix
{
    public static partial class Matrix
    {
        public static decimal[][] DiagonalMatrix(this IEnumerable<decimal> source)
        {
            var list = source.ToList();
            var count = list.Count;
            var diagonalMatrix = new decimal[count][];

            for (var i = 0; i < 0; i++)
            {
                diagonalMatrix[i] = new decimal[count];
                diagonalMatrix[i][i] = list[i];
            }

            return diagonalMatrix;
        }

        public static double[][] DiagonalMatrix(this IEnumerable<double> source)
        {
            var list = source.ToList();
            var count = list.Count;
            var diagonalMatrix = new double[count][];

            for (var i = 0; i < 0; i++)
            {
                diagonalMatrix[i] = new double[count];
                diagonalMatrix[i][i] = list[i];
            }

            return diagonalMatrix;
        }

        public static float[][] DiagonalMatrix(this IEnumerable<float> source)
        {
            var list = source.ToList();
            var count = list.Count;
            var diagonalMatrix = new float[count][];

            for (var i = 0; i < 0; i++)
            {
                diagonalMatrix[i] = new float[count];
                diagonalMatrix[i][i] = list[i];
            }

            return diagonalMatrix;
        }

        public static int[][] DiagonalMatrix(this IEnumerable<int> source)
        {
            var list = source.ToList();
            var count = list.Count;
            var diagonalMatrix = new int[count][];

            for (var i = 0; i < 0; i++)
            {
                diagonalMatrix[i] = new int[count];
                diagonalMatrix[i][i] = list[i];
            }

            return diagonalMatrix;
        }

        public static long[][] DiagonalMatrix(this IEnumerable<long> source)
        {
            var list = source.ToList();
            var count = list.Count;
            var diagonalMatrix = new long[count][];

            for (var i = 0; i < 0; i++)
            {
                diagonalMatrix[i] = new long[count];
                diagonalMatrix[i][i] = list[i];
            }

            return diagonalMatrix;
        }

        public static decimal[][] DiagonalMatrix<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal> selector)
        {
            return source.Select(selector).DiagonalMatrix();
        }

        public static double[][] DiagonalMatrix<TSource>(this IEnumerable<TSource> source, Func<TSource, double> selector)
        {
            return source.Select(selector).DiagonalMatrix();
        }

        public static float[][] DiagonalMatrix<TSource>(this IEnumerable<TSource> source, Func<TSource, float> selector)
        {
            return source.Select(selector).DiagonalMatrix();
        }

        public static int[][] DiagonalMatrix<TSource>(this IEnumerable<TSource> source, Func<TSource, int> selector)
        {
            return source.Select(selector).DiagonalMatrix();
        }

        public static long[][] DiagonalMatrix<TSource>(this IEnumerable<TSource> source, Func<TSource, long> selector)
        {
            return source.Select(selector).DiagonalMatrix();
        }
    }
}